package io.kiki.task.client.common.threadlocal;

import cn.hutool.core.lang.Assert;
import io.kiki.task.client.common.ThreadLocal;
import io.kiki.task.client.common.exception.ClientException;

/**
 * ThreadLocal实现类
 *
 * @author huihui
 */
public class CommonThreadLocal<T> implements ThreadLocal<T> {

    private final java.lang.ThreadLocal<T> threadLocal;

    public CommonThreadLocal(java.lang.ThreadLocal<T> threadLocal) {
        Assert.notNull(threadLocal, () -> new ClientException("thread local can not be null"));
        this.threadLocal = threadLocal;
    }

    @Override
    public void set(T value) {
        threadLocal.set(value);
    }

    @Override
    public void remove() {
        threadLocal.remove();
    }

    @Override
    public T get() {
        return threadLocal.get();
    }
}
